<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>取款</title>
    <link href="res/style.css" rel="stylesheet">
    <script src="js/vue.min.js"></script>
    <script src="js/axios.min.js"></script>
</head>
<body>
<div id="app" class="flex">
    <main>
        <header class="flex">
            <div>
                <h3>源辰银行</h3>
                <small>ycinfo bank</small>
            </div>
            <div id="contact">
                <div>客服电话: 8888</div>
                <div>网址: www.ycinfo.bank.com</div>
            </div>
        </header>
        <div class="msg">
            倒计时: <h2>32</h2> 秒
        </div>
        <div id="pane" class="flex">
            <div class="btns">
                <a class="left" @click="withdraw(100)">100</a>
                <a class="left" @click="withdraw(500)">500</a>
                <a class="left" @click="withdraw(1000)">1000</a>
            </div>
            <div id="info">
                <h2>取款服务</h2>
                <form action="main.html">
                    <input placeholder="输入金额" type="number" v-model="money"><br>
                </form>
            </div>
            <div class="btns">
                <a class="right">2000</a>
                <a class="right">5000</a>
                <a class="right" @click="withdraw(money)">确定</a>
                <a href="main.html" class="right">返回</a>
            </div>
        </div>
    </main>
</div>
</body>
</html>

<script>
    new Vue({
        el: "#app",
        data: {
            money: 0
        },
        methods: {
            withdraw(money) {
                let params = new URLSearchParams()
                if (money === 0 || money === "") {
                    alert("请输入金额")
                    return
                }
                params.append("money", money)
                axios.post("bank/withdraw", params).then(res => {
                    if (res.data.code === 200) {
                        alert("取款成功")
                        setTimeout(() => {
                            location.href = "main.html";
                        }, 1000)
                    } else {
                        alert("取款失败")
                    }
                }).catch(err => {
                    alert("系统错误，请联系管理员")
                })
            },

        }
    })
</script>
